﻿using B.S.Ingredients.APIRead.Application.Command.SlaughterCommand;
using B.S.Ingredients.Domain;
using B.S.Ingredients.ErrorCode;
using B.S.Ingredients.Infartructrue.Interfaces;
using MediatR;

namespace B.S.Ingredients.APIRead.Application.CommandHandler.SlaughterHandler
{
    public class SlaughterCreateCommandHandler : IRequestHandler<SlaughterCreateCommand, APIResult<int>>
    {
        public SlaughterCreateCommandHandler(IBaseRepository<Slaughter> slaughterRepository)
        {
            SlaughterRepository = slaughterRepository;
        }

        public IBaseRepository<Slaughter> SlaughterRepository { get; }

        public async Task<APIResult<int>> Handle(SlaughterCreateCommand request, CancellationToken cancellationToken)
        {
            var path =await SlaughterRepository.CreateAsync(request.Data);
            return new APIResult<int>
            {
                Code = ResultCode.success,
                Mag = "",
                Data = path
            };
        }
    }
}
